home *** CD-ROM | disk | FTP | other *** search
- /* Here are the AppleEvent handlers for this background-only task. */
- /* Since this is a real live application, it can accept and send any */
- /* Apple Events you want to send or recieve. */
- /* In this case, the only ones that make any sense in this app are */
- /* 'oapp' and 'quit' */
-
- #include "AEDaemon.h"
- extern Boolean gQuit;
- extern EventRecord ERecord;
- extern Boolean gHasAppleEvents;
-
- /* InitAEStuff checks for the availability of the AppleEvent Manager and */
- /* installs our event handlers. */
- /* if the AEM isn't around, we bail. */
- void InitAEStuff(void)
- {
-
- OSErr aevtErr = noErr;
- long aLong = 0;
- Boolean gHasAppleEvents = false;
- /* Check this machine for AppleEvents. If they are not here (ie not 7.0)
- * then we exit */
- gHasAppleEvents = (Gestalt(gestaltAppleEventsAttr, &aLong) == noErr);
- /* The following series of calls installs all our AppleEvent Handlers.
- * These handlers are added to the application event handler list that
- * the AppleEvent manager maintains. So, whenever an AppleEvent happens
- * and we call AEProcessEvent, the AppleEvent manager will check our
- * list of handlers and dispatch to it if there is one.
- */
- if (gHasAppleEvents) {
-
- aevtErr = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
- NewAEEventHandlerProc(AEOpenHandler),0, false);
- if (aevtErr) ExitToShell();
-
- aevtErr = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
- NewAEEventHandlerProc(AEOpenDocHandler),0, false);
- if (aevtErr) ExitToShell();
-
- aevtErr = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
- NewAEEventHandlerProc(AEQuitHandler), 0, false);
- if (aevtErr) ExitToShell();
-
- aevtErr = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
- NewAEEventHandlerProc(AEPrintHandler),0, false);
- if (aevtErr) ExitToShell();
- } else {
- ExitToShell();
- }
- }
-
- /* end InitAEStuff */
-
- void DoHighLevel(EventRecord *AERecord)
- {
- /* I'm not doing any error handling here because there's not a lot */
- /* I can do, just pass the errors back. */
- AEProcessAppleEvent(AERecord);
-
- }
-
- /* end DoHighLevel */
-
-
- /* This is the standard Open Application event. */
- pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- #pragma unused (messagein,reply,refIn)
- /* we of course don't do anything here, since we're background only */
- return(noErr);
- }
-
- /* end AEOpenHandler */
-
- /* Open Doc, opens our documents. */
- /* In this case, of course, you are in the background so you should return an error */
- /* here since you're not opening a document. */
- /* Of course, you _might_ want to open a doc, but you will probably */
- /* confuse the user if you do, since they will see no action as the */
- /* result of their clicking on a document icon. */
- pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- #pragma unused (reply, refIn,messagein)
- /* we of course don't do anything here, so tell the sender that we */
- /* didn't handle the event */
- return(errAEEventNotHandled);
- }
-
- pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- #pragma unused (reply,refIn,messagein)
- /* we of course don't do anything here */
- return(errAEEventNotHandled);
- }
-
- /* Standard Quit event handler, to handle a Quit event from the Finder, for example. */
- /* ••••• DO NOT CALL EXITTOSHELL HERE ••••• or you will never have a happy life. */
- pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- #pragma unused (messagein,refIn,reply)
- /* This does _NOT_ quit, you */
- /* should NEVER quit from an AppleEvent handler. Calling */
- /* ExitToShell here would blow things up */
- gQuit = true;
- return(noErr);
- }
-
-